package com.eternal.permission.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.eternal.Exception.ResultVo;
import com.eternal.permission.entity.RoleInfo;
import com.eternal.permission.service.RoleInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 基础角色表 前端控制器
 * </p>
 *
 * @author Eternal
 * @since 2018-08-26
 */
@RestController
@RequestMapping("/roleInfo")
public class RoleInfoController {

    @Autowired
    private RoleInfoService roleInfoService;


    @GetMapping("/queryRoleInfoPage")
    @RequiresPermissions("system_permission_role_query")
    public ResultVo<Page<RoleInfo>> queryRoleInfoPage(@RequestParam(required = true) Integer current, @RequestParam(required = true) Integer size) {
        Page<RoleInfo> page = new Page<>(current, size);
        Page<RoleInfo> roleInfos = roleInfoService.getRoleInfo(page);
        return new ResultVo(roleInfos);
    }

    @GetMapping("/queryRoleInfoById")
    @RequiresPermissions("system_permission_role_queryRoleInfoById")
    public ResultVo<RoleInfo> queryRoleInfoById(@RequestParam(required = true) String roleId) {
        RoleInfo roleInfo = roleInfoService.getRoleInfo(roleId);
        return new ResultVo(roleInfo);
    }

    @PostMapping("/modifyIsOpen")
    @RequiresPermissions("system_permission_role_modifyIsOpen")
    public ResultVo modifyIsOpen(@RequestBody RoleInfo roleInfo) {
        int modify = roleInfoService.modifyIsOpen(roleInfo);
        return new ResultVo(modify);
    }

}

